package com.qdu.driver;
import com.qdu.bean.RentCarBean;
import com.qdu.mapper.Top5CountByHourMapper;
import com.qdu.reducer.Top5CountByHourReducer;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

public class Top5CountByHourDriver {
    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
        args = new String[] { "D:/train.csv", "D:/output6" };
        Configuration conf = new Configuration();

        Job job = Job.getInstance(conf);

        job.setJarByClass(Top5CountByHourDriver.class);

        job.setMapperClass(Top5CountByHourMapper.class);
        job.setReducerClass(Top5CountByHourReducer.class);

        job.setMapOutputKeyClass(IntWritable.class);
        job.setMapOutputValueClass(IntWritable.class);

        job.setOutputKeyClass(IntWritable.class);
        job.setOutputValueClass(IntWritable.class);

//        FileInputFormat.addInputPath(job, new Path(args[0]));
//        FileOutputFormat.setOutputPath(job, new Path(args[1]));

        FileInputFormat.setInputPaths(job,args[0]);
        Path outputPath=new Path(args[1]);
        FileSystem fs=FileSystem.get(conf);
        if (fs.exists(outputPath)){
            fs.delete(outputPath,true);
        }
        FileOutputFormat.setOutputPath(job,outputPath);
        boolean result = job.waitForCompletion(true);
        System.exit(result ? 0 : 1);
    }
}
